$("#addfrd").click(function()
{
	$("#addboard").css("display","block");
});


$(".tiny").click(function()
{
	$("#addboard").css("display","none");
});

$(".close").click(function()
{
	$("#tabf").find("input").val("输入好友账号，昵称等条件查找");
	$("#tabf").find("input").css("color","#CCCCCC");
	$("#tabg").find("input").val("输入群账号，群名称等条件查找");
	$("#tabg").find("input").css("color","#CCCCCC");
	$("#tabf").find(".find").html("");
	$("#tabg").find(".right").html("");
	$(".f").css("backgroundColor","#0099CC");
	$(".g").css("backgroundColor","#0099CC");

	$("#addboard").css("display","none");

});


//切换面板
$(".f").click(function()
{
	$("#tabg").css("display","none");
	$("#tabf").css("display","block");
	$(".f").css("backgroundColor","#99CCFF");
	$(".g").css("backgroundColor","#0099CC");
});

$(".g").click(function()
{
	$("#tabf").css("display","none");
	$("#tabg").css("display","block");
	$(".f").css("backgroundColor","#0099CC");
	$(".g").css("backgroundColor","#99CCFF");
});




/*
搜索好友与群组框点击回车查询事件----------------------------------------
*/

//搜索框获取焦点事件

//防止同一字符串查询两次
tempvar.thisfval="";
$("#sfrd").focus(function(e)
{
	var str="输入好友账号，昵称等条件查找";
	var t=$(this);
	
	if($(this).val()==str)
	{
		$(this).val("");
		$(this).css('color','black');
	}
	$(window).keydown(function(e)
	{	

		if(e.keyCode=="13")
		{
			$("#searchfrd").trigger("click");
		}
	});
}).focusout(function()
{
	if($.trim($(this).val())=="")
	{
		$(this).val("输入好友账号，昵称等条件查找");
		$(this).css('color','#CCCCCC');
	}
});
//搜索好友方法
$("#searchfrd").click(function()
{
	//alert("e");
	var str="输入好友账号，昵称等条件查找";
	var val=$("#sfrd").val();
	if(tempvar.thisfval==val)
	{
		return;
	}	
	if($.trim(val)!=""&&val!=str)
	{
		//alert("查询好友中");
		tempvar.thisfval=val;
		//提交查询
		searchnew('get=frd&&kw='+$.trim(val),function(msg)
		{
			if(msg=="no")
			{
				$("#tabf").find(".find").html("<div class='noresault'>没有找到您需要的结果哦</div>");
				return false;
			}
			
			var html=$("#tabf").find(".find").html();
			//如果是单条记录
			if(msg.uid)
			{
				console.log(gbl.user);
				console.log(msg);
				msg.img=msg.img==""?"暂无":msg.img;
				msg.info=msg.info==""?"他暂时没有填写简介哦":msg.info;
				html="<div class='fcard' id='add"+msg.uid+"'>";
				html+="<div class='img'>"+msg.img+"</div>";
				html+="<div class='name'>"+msg.name+"</div>";
				html+="<div class='info'>"+msg.info+"</div>";
				
				if(msg.isfrd==-1)
				{
					html+='<div class="addbtn">自己';
				}
				else if(msg.isfrd==0)
				{
					html+='<div class="addbtn canadd">+添加';
				}
				else if(msg.isfrd==1)
				{
					html+='<div class="addbtn openfrd">已为好友';
				}
				html+='</div></div>';
				$("#tabf").find(".find").html(html);

			}
			//如果是多条记录
			else if(msg[0].uid)
			{
				//console.log(msg[0].uid);
				var html="";
				for(var v in msg)
				{
					//console.log(msg[v].name);
					msg[v].img=msg[v].img==""?"暂无":msg[v].img;
					msg[v].info=msg[v].info==""?"他暂时没有填写简介哦":msg[v].info;
					html+="<div class='fcard' id='add"+msg[v].uid+"'>";
					html+="<div class='img'>"+msg[v].img+"</div>";
					html+="<div class='name'>"+msg[v].name+"</div>";
					html+="<div class='info'>"+msg[v].info+"</div>";
					
					if(msg[v].isfrd==-1)
					{
						html+='<div class="addbtn">自己';
					}
					else if(msg[v].isfrd==0)
					{
						html+='<div class="addbtn canadd">+添加';
					}
					else if(msg[v].isfrd==1)
					{
						html+='<div class="addbtn openfrd">已为好友';
					}
					html+='</div></div>';
				}
				$("#tabf").find(".find").html(html);
			}
			//绑定添加好友方法
			$(".canadd").bind('click',_show_add_frd);
		});
	}
	
});

//防止同一字符串查询两次
tempvar.thisgval="";
$("#sgrp").focus(function(e)
{
	var str="输入群账号，群名称等条件查找";
	var t=$(this);
	
	if($(this).val()==str)
	{
		$(this).val("");
		$(this).css('color','black');
	}
	$(window).keydown(function(e)
	{
		
		if(e.keyCode=="13")
		{
			$("#searchgrp").trigger("click");
		}
	});
}).focusout(function()
{
	if($.trim($(this).val())=="")
	{
		$(this).val("输入群账号，群名称等条件查找");
		$(this).css('color','#CCCCCC');
	}
});
//搜索群组方法
$("#searchgrp").click(function()
{
	//alert("e");
	var str="输入群账号，群名称等条件查找";
	var val=$("#sgrp").val();
	if(tempvar.thisgval==val)
	{
		return;
	}	
	if($.trim(val)!=""&&val!=str)
	{
		//alert("查询群中");
		tempvar.thisgval=val;
		//提交查询
		searchnew('get=grp&&kw='+$.trim(val),function(msg)
		{
			if(msg=="no")
			{
				$("#tabg").find(".find").html("<div class='noresault'>没有找到您需要的结果哦</div>");
				return false;
			}


		});
	}
});


function searchnew(sdata,scs)
{
	var s={
	url:'searchfg.php',
	dataType:'json',
	type:'POST',
	data:'u='+gbl.user+'&&'+sdata,
	success:scs
	};
	$.ajax(s);
}

//--------------------------------------------------------------------

/*
添加好友功能
1,点击添加按钮 请求对方是否设置了加好友权限
(uid（待添加好友的uid）
->
setting_addfrd[said,uid,deftype,question]
(table)setting_addfrd:deftype(权限 0直接添加(默认，一般对没有设置添加权限或对方【无论有没有设置权限】已加你但你没有加对方，都为0) 1介绍自我验证 2回答正确回答问题 3回答多个问题待好友审核)
->
(table)setting_addfrd:question(deftype0为空，deftype1为分号分隔的2个字符串[问题;标准答案]，deftype2为分号分隔的多个字符串[问题1;问题2;问题3;...])
)

（如果deftype1，保存标准答案，待我方填答案后判断是否正确）

2,根据对方设置的权限填写完信息后，提交到
	添加好友表（table）addfrdmsg[aflid,ownid,frdid,answer,reason,isread=0(给好友看的),add_or_not=-1,done=0(给我方轮询看的)]
	待添加好友阅读此信息后(isread=1)，判断是否添加你为好友(add_or_not)

	两方的网页轮询或隔询会拉取本条加好友消息，好友方isread=1则不再读取,我方done=1则不再读取

	如果点击添加按钮:
	好友方:则弹出该好友的分组，判断将你加入到哪个分组，再插入到frd表，并动态插入网页
	我方:轮询或隔询拉取到add_or_not=1,则插入frd表，并动态插入网页
	如果拒绝:
	好友方:isread=1,add_or_not=0,提交拒绝理由reason="XXXX",不再读取
	我方:轮询或隔询收到拒绝提示，并显示拒绝理由reason ,可以再次添加，重复上述步骤
*/
//1,添加点击功能
function _show_add_frd()
{
	/*var addid=$(this).parent(".fcard").attr("id");
	var fid=addid.replace("add","");

	_frdobj.img=$(this).siblings(".img").html();
	_frdobj.name=$(this).siblings(".name").html();
	var str=$(this).siblings(".info").html();
	var arr=str.split(",");
	_frdobj.sex=arr[0];
	_frdobj.address=arr[1];
	console.log(_frdobj);


	//先显示‘输入我的介绍’，再在其下方显示获取来的‘添加问题’

	
	_add_frd(fid,'getdef',function(msg){
		console.log("msg="+msg);
		if(msg=="no")
		{
			console.log("_add_frd:msg="+msg);
		}
		else if(msg==0)
		{
			$("#addfrdbox").css("display","block");
			$("#add_operation").find(".validate1").css("display","block");
			//$("#addfrdbox>.addfrdbar>.text").html("<img src='img/qq1.png'/>"+我的名字+" 添加好友");
			$("#addwho").find(".addimghead").html("<img src='"+_frdobj.img+"'/>");
			$("#addwho>.adddetail>ul").append("<li class='b'>"+_frdobj.name+"</div>");
			$("#addwho>.adddetail>ul").append("<li class='black'>"+_frdobj.account+"</div>");
			$("#addwho>.adddetail>ul").append("<li class='light'>性别:"+_frdobj.sex+"</div>");
			$("#addwho>.adddetail>ul").append("<li class='light'>年龄:"+_frdobj.age+"</div>");
			$("#addwho>.adddetail>ul").append("<li class='light'>所在地:"+_frdobj.address+"</div>");

			$("#addfrdbox>.gotoaddfrd>.nextbtn").css("display","block");
			$("#addfrdbox>.gotoaddfrd>.closebtn").css("display","block");
			
		}
		else
		{
			if(typeof(msg.question)==String)
			{

			}
			else if(typeof(msg.question[0])==String)
			{

			}
			else
			{
				console.log("_add_frd:msg="+msg);
			}
		}
	});
	*/


	new FrdBox($(this)).init();
	
}

function _add_frd(fid,method,func)
{
	console.log("_add_frd");
	var s=
	{
		url:'addfrd.php',
		type:'POST',
		data:'u='+gbl.user+'&&f='+fid+'&&method='+method,
		dataType:'json',
		success:func
	}
	$.ajax(s);
}

function FrdBox(obj)
{
	this.obj=obj;
	//var _def="";
	//现在在哪
	var nowin="";
	//保存需要提交的信息
	var postmsg=new Array();

	//添加好友对象
	var _frdobj=
	{
		account:"",
		age:"-",
		sex:"-",
		address:"--",
		img:"",
		name:"",
		deftype:0,
	};

	this.init=function()
	{
		this._createbox();
		//this._bind();
	}

	this._createbox=function()
	{
		var addid=this.obj.parent(".fcard").attr("id");
		var fid=addid.replace("add","");
		postmsg['fid']=fid;
		console.log("addid="+addid+" fid="+fid);
		console.log(this.obj.siblings(".img").html());
		_frdobj.img=this.obj.siblings(".img").html();
		_frdobj.name=this.obj.siblings(".name").html();
		//postmsg['name']=this._frdobj.name;
		var str=this.obj.siblings(".info").html();
		var arr=str.split(",");
		_frdobj.sex=arr[0];
		_frdobj.address=arr[1];
		console.log(_frdobj);
		//添加主体框
		$('body').append(
			'<div id="addfrdbox">'+
			'<div class="addfrdbar">'+
			"<div class='text'><img src='img/qq1.png'/>"+ '辣椒哥'+" 添加好友</div>"+
			'<div class="closeadd">X</div>'+
			'<div class="tinyadd">-</div>'+
			'</div>'+
			'<div id="addwho">'+
			'<div class="changecolor"></div>'+
			'<div class="addimghead">'+_frdobj.img+'</div>'+
			'<div class="adddetail">'+
			'<ul>'+
			'<li class="b">'+_frdobj.name+'</li>'+
			'<li class="black">'+_frdobj.account+'</li>'+
			'<li class="light">性别:'+_frdobj.sex+'</li>'+
			'<li class="light">年龄:'+_frdobj.age+'</li>'+
			'<li class="light">所在地：'+_frdobj.address+'</li>'+
			'</ul></div></div>'+
			"<div id='add_operation'><img class='loadingv' src=''//></div>"+
			'<div class="gotoaddfrd">'+
			'<div class="donebtn">完成</div>'+
			'<div class="closebtn">关闭</div>'+
			'<div class="cancelbtn">取消</div>'+
			'<div class="nextbtn">下一步</div></div></div>'
		);
		//$("#addfrdbox").css("display","block");

		_add_frd('f='+fid,'getdef',function(msg){
			//存储权限信息
			//_def=msg;
			
			console.log("msg="+msg);
			if(msg=="no")
			{
				console.log("_add_frd:msg="+msg);
			}
			else if(msg==0)
			{
				nowin=0;
				
				//存储权限信息
				_frdobj.deftype=0;
				//直接跳页到addset
				_nextpage();
				//$("#addfrdbox>.gotoaddfrd>.nextbtn").css("display","block");
				//$("#addfrdbox>.gotoaddfrd>.closebtn").css("display","block");
			}
			else if(msg==1)
			{
				$("#add_operation").empty();

				$("#add_operation").html(
				'<div class="validate1">'+
				'<p>请输入验证信息:</p>'+
				'<textarea class="myintro">我是...</textarea>'+
				'</div>'	
				);
				
				$("#addfrdbox>.gotoaddfrd>.nextbtn").css("display","block");
				$("#addfrdbox>.gotoaddfrd>.closebtn").css("display","block");
				$("#addfrdbox>.gotoaddfrd>.cancelbtn").css("display","none");
				$("#addfrdbox>.gotoaddfrd>.donebtn").css("display","none");
				$("#addfrdbox").css("display","block");
				//存储权限信息
				_frdobj.deftype=1;
				//设置当前位置
				nowin="v1";
			}
			else
			{
				if(msg.deftype==2)
				{
					$("#add_operation").empty();
					//保存问题和答案到postmsg
					postmsg['question']=msg.question;
					postmsg['answer']=msg.answer;
					
					$("#add_operation").append(
					'<div class="validate2">'+
					'<p>对方需要您回答一下验证问题:</p>'+
					'<div class="question_only">'+msg.question+'</div>'+
					'<input type="text" />'+
					'<div class="isright"></div></div>'
					);


					//设置显示按钮
					$("#addfrdbox>.gotoaddfrd>.nextbtn").css("display","block");
					$("#addfrdbox>.gotoaddfrd>.closebtn").css("display","block");
					$("#addfrdbox>.gotoaddfrd>.cancelbtn").css("display","none");
					$("#addfrdbox>.gotoaddfrd>.donebtn").css("display","none");
					//存储权限信息
					_frdobj.deftype=2;
					//设置当前位置
					nowin="v2";
				}
				else if(msg.deftype==3)
				{
					$("#add_operation").empty();
					$("#add_operation").append(
					'<div class="validate3"><p>对方需要您回答'+msg.question.length+'个验证问题:</p><ul></ul></div>'	
					);

					postmsg['question']='';

					//循环时将问题加入postmsg,并添加问题
					for (var i=0;i<msg.question.length;i++)
					{
						postmsg['question']+=msg.question[i]+";";
						$(".validate3>ul").append(
						'<li>问题'+(i+1)+':&nbsp;&nbsp;'+msg.question[i]+
						'<input type="text" class="answers" /></li>'	
						);
					}
					

					//设置显示按钮
					$("#addfrdbox>.gotoaddfrd>.nextbtn").css("display","block");
					$("#addfrdbox>.gotoaddfrd>.closebtn").css("display","block");
					$("#addfrdbox>.gotoaddfrd>.cancelbtn").css("display","none");
					$("#addfrdbox>.gotoaddfrd>.donebtn").css("display","none");
					//存储权限信息
					_frdobj.deftype=3;
					//设置当前位置
					nowin="v3";
				}
				else
				{
					console.log("_add_frd:msg="+msg);
				}
			}
			//绑定组件事件
			_bind();
		});
	}
	//发送请求公共方法
	var _add_frd=function(sendstr,method,func,async)
	{
		var ac=arguments[3]==undefined?true:arguments[3];
		console.log("_add_frd");
		var s=
		{
			url:'addfrd.php',
			type:'POST',
			data:'u='+gbl.user+'&&method='+method+"&&"+sendstr,
			dataType:'json',
			async:ac,
			success:func
		}
		$.ajax(s);
	}
	
	var _bind=function()
	{
		
		$("#add_operation>.validate1>.myintro").focus(function()
		{	
			nowin="v1";
			if($(this).val()=="我是...")
			{
				$(this).val("");
				$(this).css("color","black");
				$(this).css('borderColor',"#CCCCCC");
			}
		}).focusout(function(){
			if($.trim($(this).val())=="")
			{
				$(this).val("我是...");
				$(this).css("color","#999999");
				$(this).css('borderColor',"red");
			}
			if($.trim($(this).val())=="我是...")
			{
				$(this).css('borderColor',"red");
			}
		});
		
		//点击好友分组显示或关闭好友列表
		$(".grphead").bind('click',function()
		{
			if($(this).siblings(".frdcontent").css("display")=="none")
			{
				$(this).siblings(".frdcontent").css("display","block");
			}
			else
			{
				$(this).siblings(".frdcontent").css("display","none");
			}
		});
		//绑定回答框失焦事件
		$(".answers").focusout(function()
		{
			if($.trim($(this).val())=="")
			{
				$(this).css("borderColor","red");
			}
			else
			{
				$(this).css("borderColor","#CCCCCC");
			}
		});
		

		/*
		下一步按钮操作
		*/
		$("#addfrdbox>.gotoaddfrd>.nextbtn").click(function()
		{
			if(nowin=="v1")
			{
				var value=$(".validate1>.myintro").val();
				console.log(value);
				if($.trim(value)==""||$.trim(value)=="我是...")
				{
					$(".validate1>.myintro").css("borderColor","red");
					return;
				}
				//保存自我介绍内容到待发送数组
				postmsg['answer']=value;
				//跳到下页
				_nextpage();
			}else if(nowin=="v2")
			{
				var answer=$(".validate2>input").val();
				//判断答案是否正确
				if($.trim(answer)==$.trim(postmsg['answer']))
				{
					postmsg['question']=postmsg['question']+";"+postmsg['answer'];
					postmsg['answer']=$.trim(answer);
					_nextpage();
				}
				else
				{
					//显示答案错误
					$(".validate2>.isright").html("回答错误");
					return;
				}
			}
			else if(nowin=="v3")
			{
				postmsg['answer']='';
				for(var i=0;i<$(".answers").length;i++)
				{
					
					var v=$(".answers").eq(i).val();
					if($.trim(v)=="")
					{
						$(".answers").eq(i).css('borderColor',"red");
						postmsg['answer']='';
						return false;
					}
					else
					{
						postmsg['answer']+=$.trim(v)+";";
					}
				}
				_nextpage();
			}
			else if(nowin=="addset")
			{

				postmsg['bakname']=$(".bakname>input").val();
				
				postmsg['togrp']=$(".togrp>.selectgrp").val();
				//如果分组为undefined,则为0
				postmsg['togrp']=postmsg['togrp']==undefined?0:postmsg['togrp'];
	
				postmsg['acc_or_not']=$(".acc_or_not").find("input[type='checkbox']").is(":checked");
				postmsg['acc_or_not']=postmsg['acc_or_not']==true?1:0;
				console.log("postmsg"+postmsg+" 等待发送添加好友请求....");
				if(_frdobj.deftype==0)
				{
					//如果是直接添加
					_nextpage(0);
				}
				else
				{
					_nextpage(1);
				}
			}
			
		});


		$("#addfrdbox>.gotoaddfrd>.closebtn").click(function()
		{
			$(this).parent('.gotoaddfrd').parent('#addfrdbox').remove();
			//$('#addfrdbox').empty();
			//$('#addfrdbox').css('display','none');
			//$('body').remove('#addfrdbox');
		});
		$("#addfrdbox>.gotoaddfrd>.cancelbtn").click(function()
		{
			$(this).parent('.gotoaddfrd').parent('#addfrdbox').remove();
			//$('#addfrdbox').empty();
			//$('#addfrdbox').css('display','none');
			//$('body').remove('#addfrdbox');
		});
		$("#addfrdbox>.gotoaddfrd>.donebtn").click(function()
		{
			$(this).parent('.gotoaddfrd').parent('#addfrdbox').remove();
			//$('#addfrdbox').empty();
			//$('#addfrdbox').css('display','none');
			//$('body').remove('#addfrdbox');
		});

		
	}
	
	//此【方法绑定】对象是给创建对象之后创建的组件绑定的方法集合
	var bind={

		addnewgrp:function()
		{
			_addgrpbox._init();
		}
		,
		checkthis:function()
		{
			//console.log('点击了');
			if($(this).find(':checkbox').attr("checked")==false||$(this).find(':checkbox').attr("checked")==undefined)
			{
				$(this).find(':checkbox').attr("checked",true);
			}
			else
			{
				$(this).find(':checkbox').attr("checked",false);
			}
		}
		,
		
	}

	var _nextpage=function(flag)
	{
		if(nowin=="0"||nowin=="v1"||nowin=="v2"||nowin=="v3")
		{
			//清空所有内容
			$("#add_operation").empty();

			//获取本用户所有好友分组
			var select=_getgrp();
			//console.log(select);
			//添加信息
			$("#add_operation").append(
			'<div class="addset">'+
			'<div class="bakname">备注姓名:&nbsp;<input type="text"/></div>'+
			'<div class="togrp">分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;组:&nbsp;'+
			select+	
			'&nbsp;<a href="javascript:;" id="addfrdgrp">新建分组</a></div>'+
			'<div class="acc_or_not"><input type="checkbox" />不允许此人访问我的空间</div></div>'	
			);
			
			//新建好友分组
			$(".togrp>a").bind('click',bind.addnewgrp);
			//绑定不允许访问空间按钮
			$(".acc_or_not").bind('click',bind.checkthis);

			
			
			//显示所需按钮
			$("#addfrdbox>.gotoaddfrd>.nextbtn").css("display","block");
			$("#addfrdbox>.gotoaddfrd>.closebtn").css("display","none");
			$("#addfrdbox>.gotoaddfrd>.cancelbtn").css("display","block");
			$("#addfrdbox>.gotoaddfrd>.donebtn").css("display","none");

			//设置nowin为当前位置
			nowin="addset";
		}
		else if(nowin=="addset")
		{
			//清空所有内容
			$("#add_operation").empty();
			//显示添加成功或者等待好友验证
			if(flag)
			{
				//发送验证后等待好友回复再看是否添加
				var str="v="+_frdobj.deftype+"&&togrp="+postmsg['togrp']+"&&fid="+postmsg['fid']+"&&aon="+postmsg['acc_or_not']+"&&bakname="+postmsg['bakname']+"&&question="+postmsg['question']+"&&answer="+postmsg['answer'];
				_add_frd(str,'sendaddfrd',function(msg){
					if(msg=="wait")
					{
						$("#add_operation").append(
						'<div class="waitaddresult">'+
						'<div class="waitmsg">'+
						'<img src="img/add48.png"/>'+
						'您已向<font>'+_frdobj.name+'</font>发送添加好友请求，请耐心等待回复'+
						'</div>'+
						'<div class="newfrds">'+
						'<div class="headtool">'+
						'<div class="title">您可能还认识这些人:</div>'+
						'<div class="switchnew">换一批</div>'+
						'</div>'+
						'<div class="new4frd">'+
						'<ul></ul></div></div></div>'
						);
					}else
					{
						$("#add_operation").append(
						'<div class="waitaddresult">'+
						'<div class="waitmsg">'+
						'<img src="img/add48.png"/>'+
						'添加<font>'+_frdobj.name+'</font>为好友失败，请检查是否已经添加过该好友'+
						'</div>'+
						'<div class="newfrds">'+
						'<div class="headtool">'+
						'<div class="title">您可能还认识这些人:</div>'+
						'<div class="switchnew">换一批</div>'+
						'</div>'+
						'<div class="new4frd">'+
						'<ul></ul></div></div></div>'
						);
					}
					
				});
				//显示所需按钮
			$("#addfrdbox>.gotoaddfrd>.nextbtn").css("display","none");
			$("#addfrdbox>.gotoaddfrd>.closebtn").css("display","none");
			$("#addfrdbox>.gotoaddfrd>.cancelbtn").css("display","none");
			$("#addfrdbox>.gotoaddfrd>.donebtn").css("display","block");

			}
			else
			{
				//发送验证并直接添加
				var str="v=0&&togrp="+postmsg['togrp']+"&&fid="+postmsg['fid']+"&&aon="+postmsg['acc_or_not']+"&&bakname="+postmsg['bakname'];
				if(postmsg['togrp']==0)
				{
					if(!$(".groups").is("#g0"))
					{
						$("#grplist").prepend("<div class='groups' id='g0'><div class='grphead'>默认分组</div><div class='frdcontent'><ul></ul></div></div>");
					}
				}
				console.log(str);
				console.log("验证0直接添加:pomsg="+postmsg);
				/*
				//发送请求时，返回好友的所有信息
				_add_frd(str,'sendaddfrd',function(newfrd){
					//完成后，将好友动态添加到指定分组
					if(newfrd.uid)
					{
						
						var html="<li class='fds' id='f"+newfrd.uid+"'>";
						html+="<div class='friend'>";
						html+="<div class='imagehead'></div>";
						if(newfrd.frdname==""||newfrd.frdname=="undefined"||newfrd.frdname==undefined)
						{
							html+="<div class='detail'>"+newfrd.name+"</div>";
						}
						else
						{
							html+="<div class='detail'>"+newfrd.name+"("+newfrd.frdname+")</div>";
						}
						html+="</div></li>";
									
						$("#g"+postmsg['togrp']+" > .frdcontent > ul").append(html);

						$("#addfrdbox>.gotoaddfrd>.nextbtn").css("display","none");
						$("#addfrdbox>.gotoaddfrd>.closebtn").css("display","none");
						$("#addfrdbox>.gotoaddfrd>.cancelbtn").css("display","none");
						$("#addfrdbox>.gotoaddfrd>.donebtn").css("display","block");
					}
					else
					{
						//提示添加失败


						$("#addfrdbox>.gotoaddfrd>.nextbtn").css("display","none");
						$("#addfrdbox>.gotoaddfrd>.closebtn").css("display","block");
						$("#addfrdbox>.gotoaddfrd>.cancelbtn").css("display","none");
						$("#addfrdbox>.gotoaddfrd>.donebtn").css("display","none");
					}
					
				},false);
				*/
				//提示添加好友成功框
				$("#add_operation").append(
				'<div class="addfrdsuccess">'+
				'<div class="succmsg">'+
				'<img src="img/yes.png"/>'+
				'您已成功添加<font>'+_frdobj.name+'</font>为好友'+
				'</div>'+
				'<div class="newfrds">'+
				'<div class="headtool">'+
				'<div class="title">您可能还认识这些人:</div>'+
				'<div class="switchnew">换一批</div>'+
				'</div>'+
				'<div class="new4frd">'+
				'<ul></ul></div></div></div>'
				);

				//更改按钮

				//这里动态请求4个推荐好友
				//需要绑定换一批事件

			}

		}

	}

	/*
	添加好友分组框
	*/
	var _addgrpbox=function()
	{
		//添加好友分组框
		//$("body").
		//绑定“确定”和“输入框”事件
		//发送添加分组请求，并动态将分组添加到select和主面板分组上
	}
	
	/*
		获取用户所有组并制成select标签
	*/
	var _getgrp=function()
	{
		var html='<select name="selectgrp" class="selectgrp">';
		html+='<option value="0">默认分组</option>';
		//同步执行ajax以免html未拼接好方法就已经跑完
		_add_frd("",'getgrp',function(msg){
			if(msg!="no")
			{
				//console.log('else');
				for(var i=0;i<msg.length;i++)
				{
					html+='<option value="'+msg[i].gid+'">'+msg[i].gname+'</option>';

				}
			}	
			
		},false);

		html+='</select>';

		return html;
	}
	
	//添加好友分组类
	var _addgrpbox=
	{
		
		_init:function()
		{
			$('body').append(
			'<div id="addgrpbox">'+
			'<div class="addgrpbar">'+
			'<div class="text"><img src="img/qq1.png"/>好友分组</div>'+
			'<div class="closeadd">X</div>'+
			'</div>'+
			'<div class="grpcontent">'+
			'<p>分组名称:</p>'+
			'<input type="text"/>'+
			'</div>'+
			'<div class="gotoaddgrp">'+
			'<div class="cancelbtn">取消</div>'+
			'<div class="acceptbtn">确定</div></div></div>'	
			);
			this._bind();
		},
		_bind:function()
		{
			$(".grpcontent>input").change(function()
			{
				$(this).trigger('focusout');
				
			}).focusout(function()
			{
				var v=$(this).val();
				if($.trim(v)=="")
				{
					$("#addgrpbox>.gotoaddgrp>.acceptbtn").css("borderColor","#999999");
					$("#addgrpbox>.gotoaddgrp>.acceptbtn").css("color","#999999");
				}
				else
				{
					$("#addgrpbox>.gotoaddgrp>.acceptbtn").css("borderColor","gray");
					$("#addgrpbox>.gotoaddgrp>.acceptbtn").css("color","#333333");
				}
			});

			$("#addgrpbox>.gotoaddgrp>.acceptbtn").mouseover(function()
			{
				if($.trim($(".grpcontent>input").val())=="")
				{
					$(this).css("borderColor","#999999");
					$(this).css("color","#999999");
				}else
				{
					$(this).css("borderColor","#0099CC");
					$(this).css("color","#0099CC");
				}

			}).mouseout(function()
			{
				if($.trim($(".grpcontent>input").val())=="")
				{
					$(this).css("borderColor","#999999");
					$(this).css("color","#999999");
				}else
				{
					$(this).css("borderColor","gray");
					$(this).css("color","#333333");
				}

			}).click(function()
			{
				//判断是否为空
				var v=$(".grpcontent>input").val();
				if($.trim(v)=="")
				{
					return;
				}
				//alert("OK");
				//提交新建分组
				var obj={
					url:'addfrd.php',
					type:'POST',
					data:'u='+gbl.user+'&&method=addgrp&&gname='+$.trim(v),
					async:false,
					success:function(msg)
					{
						if(msg!='no')
						{
							$(".togrp>.selectgrp").append('<option value="'+msg+'">'+v+'</option>');
							$("#grplist").append("<div class='groups' id='g"+msg+"'><div class='grphead'>"+v+"(0)</div><div class='frdcontent'><ul></ul></div></div>");

							$('#addgrpbox').remove();
						}
						else
						{
							$(".addgrpbar>.text").html('<img src="img/qq1.png"/>添加分组失败');
							return;
						}
					}
				};
				$.ajax(obj);

				
			});

			$("#addgrpbox>.gotoaddgrp>.cancelbtn").click(function()
			{
				$('#addgrpbox').remove();
			});
		}
	};

}